<template>
  <el-row>
    <el-col class="input-wrapper">
      <div class="input-title">设置新密码</div>
      <div class="input-box">
        <el-form ref="find">
          <nb-form
            v-model="password"
            placeholder="新密码"
            type="password"
            required="isPassword"
            prop="password"
          ></nb-form>
          <nb-form
            v-model="password2"
            placeholder="确认密码"
            type="password"
            required="isPassword"
            prop="password2"
          >
          </nb-form>
        </el-form>

      </div>
      <el-button class="confirm-btn" type="primary" @click.native="findPassword">确定</el-button>
    </el-col>
  </el-row>
</template>
<script>
  import md5 from 'md5'
  import NbForm from '@/components/nb-form.vue'
  import Mixin from '@/common/mixin'
  export default {
    data () {
      return {
        password: '',
        password2: ''
      }
    },
    mixins: [Mixin],
    props: {
      mobile: {
        type: String,
        required: true
      }
    },
    components: {
      NbForm
    },
    methods: {
      findPassword () {
        let _data = {
          param: {
            password: md5(this.password),
            mobile: this.mobile,
            entId: '1'
          }
        }
        if (this.password !== this.password2) {
          return this.$message.warning('两次密码输入不一致')
        }
        let checked = this.validator(this.$refs.find)
        !checked && (
          this.$store.dispatch('FIND_PASSWORD', _data).then(res => {
            if (res.success) {
              this.$message.success('新密码设置成功！')
              setTimeout(() => {
                this.$emit('action', 'login')
              }, 1000)
            } else {
              this.$message.error(res.msg)
            }
          })
        )
      }
    },
    mounted () {
    }
  }
</script>

<style lang="scss" scoped>
  .input-wrapper {
    width: 300px;
    box-sizing: border-box;

  .input-title {
    font-size: 24px;
    text-align: left;
    color: inherit;
    margin-bottom: 18px;
  }

  .input-box {
    .box1{
      padding: 0 6px 0 10px;
      border-left: 1px solid #d8dce5;
      cursor: pointer;
      font-size: 13px;
      color: #8f9bb2;
    }
  .box2{
    width: 78px;
    background-repeat: no-repeat;
    background-position: 4px 5px;
    background-size: contain;
    cursor: pointer;
  }


  }
  .confirm-btn {
    display: block;
    width: 100%;
    padding: 10px 20px;
    background: #2b8dff;
  }

  .forget {
    display: block;
    margin-top: 15px;
    font-size: 13px;
    color: #337ab7;
    cursor: pointer;
  }

  }
  .el-form-item{
    /*margin-bottom: 15px;*/
  }
</style>
